public class Solution553 {
    public String optimalDivision(int[] nums) {
        if (nums.length==1){
            return String.valueOf(nums[0]);
        }if (nums.length==2){
            return String.valueOf(nums[0]).concat("/").concat(String.valueOf(nums[1]));
        }else{
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append(nums[0]).append("/(");
            for (int i=1;i<nums.length;i++){
                stringBuilder.append(nums[i]).append('/');
            }
            stringBuilder.setCharAt(stringBuilder.length()-1,')');
            return stringBuilder.toString();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution553().optimalDivision(new int[]{1000,100,10,2}));
    }
}
